package com.ay.weixin.fdc.boss.user.db;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ay.weixin.fdc.boss.user.domain.FDCAgent;
import com.ay.weixin.fdc.boss.user.domain.FDCAgentDetail;

public class FDCAgentDao extends UserDao {
	
	
	public void insert(FDCAgent user) throws SQLException{
		this.sqlMapper.insert("fdc_user.insert",user);
	}
	
	public void update(FDCAgent user) throws SQLException{
		this.sqlMapper.insert("fdc_user.update",user);
	}
	
	public void updateProfile(FDCAgent user) throws SQLException{
		this.sqlMapper.update("fdc_user.updateProfile",user);
	}
	
	public FDCAgent getMyInvitor(long id) throws SQLException{
		return (FDCAgent)this.sqlMapper.queryForObject("fdc_user.getMyInvitor", id);
	}
	
	@Override
	public FDCAgent getById(long id) throws SQLException{
		return (FDCAgent)this.sqlMapper.queryForObject("fdc_user.getById", id);
	}
	
	
	public FDCAgentDetail getUserDetailById(long id) throws SQLException{
		return (FDCAgentDetail)this.sqlMapper.queryForObject("fdc_user.getUserDetailById", id);
	}
	public FDCAgent getByInviteCode(String invite_code)throws SQLException{
		return (FDCAgent)this.sqlMapper.queryForObject("fdc_user.getByInviteCode",invite_code);
	}
	
	public FDCAgent getByIDCardNo(long wxproject_id,String id_card_no)throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id_card_no", id_card_no);
		map.put("wxproject_id", wxproject_id);
		return (FDCAgent)this.sqlMapper.queryForObject("fdc_user.getByIDCardNo",map);
	}
	
	public FDCAgent getByPhone(long wxproject_id,String phone)throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("phone", phone);
		map.put("wxproject_id", wxproject_id);
		return (FDCAgent)this.sqlMapper.queryForObject("fdc_user.getByPhone",map);
		
	}
	
	public List<FDCAgent> getUserByStatus(long wxproject_id,String status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgent>)this.sqlMapper.queryForList("fdc_user.getByStatus",map);
	}
	
	public List<FDCAgent> getAllSalesmanByStatus(long wxproject_id,String status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type", "salesman");
		map.put("status", status);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgent>)this.sqlMapper.queryForList("fdc_user.getAllByStatusAndUserType",map);
	}
	

	public int countByStatus(long wxproject_id,String status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countByStatus",map);
		if(count==null)return 0;
		return count;
	}
	
	public int countByProfile(long wxproject_id,int profile_verify) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("profile_verify", profile_verify);
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countByProfile",map);
		if(count==null)return 0;
		return count;
	}
	
	public int countSearchByStatus(long wxproject_id,String status,String keywords) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("keywords", keywords);
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countSearchByStatus",map);
		if(count==null)return 0;
		return count;
	}
	
	public int countSearchByProfile(long wxproject_id,int profile_verify,String keywords) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("keywords", keywords);
		map.put("profile_verify", profile_verify);
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countSearchByProfile",map);
		if(count==null)return 0;
		return count;
	}
	
	public List<FDCAgentDetail> getUserDetailByStatus(long wxproject_id,String status,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.getUserDetailByStatus",map);
	}
	
	public List<FDCAgentDetail> getUserDetailByProfile(long wxproject_id,int profile_verify,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("profile_verify", profile_verify);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.getUserDetailByProfile",map);
	}
	
	
	public List<FDCAgentDetail> getSalesmanByStatus(long wxproject_id,String status,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type", "salesman");
		map.put("status", status);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.getByStatusAndUserType",map);
	}
	
	public int countSalesmanByStatus(long wxproject_id,String status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("type", "salesman");
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countByStatusAndUserType",map);
		if(count==null)return 0;
		return count;
	}
	
	
	public int countSalesmanSearchByStatus(long wxproject_id,String status,String keywords) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("keywords", keywords);
		map.put("type", "salesman");
		map.put("wxproject_id", wxproject_id);
		Integer count=(Integer) this.sqlMapper.queryForObject("fdc_user.countSearchByStatusAndUserType",map);
		if(count==null)return 0;
		return count;
	}
	
	
	
	public List<FDCAgentDetail> searchUserDetailByProfile(long wxproject_id,int profile_verify,String keywords,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("keywords", keywords);
		map.put("profile_verify", profile_verify);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.searchUserDetailByProfile",map);
	}
	
	public List<FDCAgentDetail> searchUserDetailByStatus(long wxproject_id,String status,String keywords,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("keywords", keywords);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.searchUserDetailByStatus",map);
	}
	
	public List<FDCAgentDetail> searchSalesmanByStatus(long wxproject_id,String status,String keywords,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type", "salesman");
		map.put("status", status);
		map.put("keywords", keywords);
		map.put("start", start);
		map.put("size", size);
		map.put("wxproject_id", wxproject_id);
		return (List<FDCAgentDetail>)this.sqlMapper.queryForList("fdc_user.searchUserDetailByStatus",map);
	}
}
